//验证只能输入数字和小数点
function clearNoNum(obj){
	//先把非数字的都替换掉，除了数字和.
	obj.value = obj.value.replace(/[^\d.]/g,"");
	//必须保证第一个为数字而不是.
	obj.value = obj.value.replace(/^\./g,"");
	//保证只有出现一个.而没有多个.
	obj.value = obj.value.replace(/\.{2,}/g,".");
	//保证.只出现一次，而不能出现两次以上
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
// 检测是否为合法数据
function isNum(str) {
	return (str.search(/^\d+(\.\d+)?$/) != -1);
}
function trim(str){
    return str.replace(/(^\s*)|(\s*$)/g,"");
  }//去掉空格



function selectAll(){
	var checkall = document.getElementById('checkall');
	var listsize = document.getElementById('listsize').value;
	for(var i=0;i<listsize;i++){
		if(checkall.checked){
			document.getElementById('checkone'+i).checked = true;
		}else{
			document.getElementById('checkone'+i).checked = false;
		}
	}
}

function deleteOneInfo(pkid,bpm_id,sel){
    
	 if(window.confirm('若该资讯下有栏目将同时删除？')){
	  window.location.href='/doTradeReg.do?pkid='+pkid+'&bpm_id='+bpm_id;
 	}
}



function chekedform() {
	var title1=document.getElementById("title").value;
	var out_link = document.getElementById("out_link").value;
	out_link = trim(out_link);
	if(title1=='')
	{
		alert('资讯标题不能为空');
		document.getElementById('title').focus();
		return false;
	}
    if(document.getElementById("cat_attr").value=="")
    {
       alert("请选择所属分类");
	   return;
    }
    var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
				+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" 
				+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" 
				+ "|" 
				+ "([0-9a-z_!~*'()-]+\.)*" 
				+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." 
				+ "[a-z]{2,6})" 
				+ "(:[0-9]{1,4})?" 
				+ "((/?)|" 
				+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
	var re = new RegExp(strRegex);
	if (out_link!=''&&!re.test(out_link))
	{
	   alert("外部链接地址的格式不正确!");
	   return;
    }

    var str=CKEDITOR.instances.content.getData();
   	str=trim(str);
    if(str=="")
	{
    	alert("资讯内容不能为空!");
    	CKEDITOR.instances.content.focus();
		return;
	}
    document.addForm.submit();
}


// 设置二级分类

function setSecondClass(val) {

	var up_class_id = val;

	Ti_channelInfo.getChClassByUpId(up_class_id, setSort2);
}

function setSort2(map_data) {

	DWRUtil.removeAllOptions("sort2");
	DWRUtil.addOptions("sort2",{"":"请选择"});
	DWRUtil.addOptions("sort2", map_data);
	$("sort3").style.display = "none";
	var item = $("sort2").length;
	if (item == 0) {
		$("sort2").style.display = "none";
	} else {
		$("sort2").style.display = "block";
	}
}
// 设置三级分类
function setTherdClass(val) {
	var up_class_id = val;
	Ti_channelInfo.getChClassByUpId(up_class_id, setSort3);
}
function setSort3(map_data) {

	if (map_data != null) {
		DWRUtil.removeAllOptions("sort3");
		DWRUtil.addOptions("sort3",{"":"请选择"});
		DWRUtil.addOptions("sort3", map_data);
		var item = $("sort3").length;
		if (item == 0) {
			$("sort3").style.display = "none";
		} else {
			$("sort3").style.display = "block";
		}
	}
}


function setTypeName1(obj){
	var idx = obj.value;
	$("class_id3").value="";
	$("class_id2").value="";
	$("class_id1").value=idx;
	Ti_channelInfo.getChNameById(idx,setClassName1);
}
function setClassName1(val) {
	$("name3").innerHTML = "";
	$("name2").innerHTML = "";
	$("name1").innerHTML = val;
}

function setTypeName2(obj){
	var idx = obj.value;
	$("class_id3").value="";
	$("class_id2").value=idx;
	Ti_channelInfo.getChNameById(idx,setClassName2);
}

function setClassName2(val) {
	$("name3").innerHTML = "";
	$("name2").innerHTML = "&nbsp; &gt; " + val + "&nbsp;";
}
function setTypeName3(obj){
	var idx = obj.value;
	$("class_id3").value=idx;
	Ti_channelInfo.getChNameById(idx,setClassName3);


}
function setClassName3(val) {
	$("name3").innerHTML = "&nbsp; &gt; " + val + "&nbsp;";
}

function ChangeClassStyle(){
	document.getElementById("flag_code").value = "1";
	document.getElementById("classId1").style.display="none";
	document.getElementById("classId2").style.display="block";
}

function formSub()
{
	var title1=document.getElementById("title").value;
	var out_link = document.getElementById("out_link").value;
	out_link = trim(out_link);
	if(title1=='')
	{
		alert('标题不能为空！');
		document.getElementById('title').focus();
		return false;
	}
	var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
			+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" 
			+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" 
			+ "|" 
			+ "([0-9a-z_!~*'()-]+\.)*" 
			+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." 
			+ "[a-z]{2,6})" 
			+ "(:[0-9]{1,4})?" 
			+ "((/?)|" 
			+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
	var re = new RegExp(strRegex);
	if (out_link!=''&&!re.test(out_link))
	{
	   alert("外部链接地址的格式不正确!");
	   document.getElementById('out_link').focus();
	   return false;
    }
    if(document.getElementById('flag_code').value == "1")
	{
	   if(document.getElementById("s_cat_attr").value==""&& document.getElementById("cat_attr").value=="")
	   {
		  alert("请选择所属分类！");
		  document.getElementById('s_cat_attr').focus();
		  return false;
	   }
	   document.getElementById("cat_attr").value = document.getElementById("s_cat_attr").value;
    }
	var str=CKEDITOR.instances.content.getData();
   	str=trim(str);
    if(str=="")
	{
    	alert("资讯内容不能为空！");
    	CKEDITOR.instances.content.focus();
		return false;
	}

	document.addForm.submit();
}

function seacher()
{
	document.indexForm.submit();
}

function changeTime(val){

	var obj = document.getElementById(val+'_operating').value;
	if( obj == '' || obj.indexOf('-')>-1 || obj=='c' || obj=='d'){
		document.getElementById(val+'_g').style.display = 'none';
	}else{
		document.getElementById(val+'_g').style.display = 'inline';
	}
}




function updatestate(val){
	var oper = document.getElementById(val+'_operating').value;
	var listsize = document.getElementById('listsize').value;
	var ifcomment='';
	var pkid_string = '';
	for(var i=0;i<listsize;i++){
		if(document.getElementById('checkone'+i).checked){
			pkid_string += document.getElementById('checkone'+i).value+'|';
		}
	}
	document.getElementById('pkid').value = pkid_string;
	if(pkid_string == ''){
		alert('请选择要操作的信息!');
		return false;
	}
	if(oper == '-')
	{
	   document.getElementById('pkid').value = pkid_string;
	   document.indexForm.action='/doTradeReg.do';
	   if(window.confirm('确认删除?'))
	   {
		  document.indexForm.submit();
	   }
	}
	else
	{
	    document.getElementById('pkid').value = pkid_string;
		document.getElementById('up_operating').value = oper;
		document.getElementById('s_start_date').value = document.getElementById(val+'_start_date').value;
		document.getElementById('s_end_date').value = document.getElementById(val+'_end_date').value;
		document.indexForm.action='/doTradeReg.do';
		document.getElementById('bpm_id').value = '2491';
		if(window.confirm('确认提交吗?'))
		{
			document.indexForm.submit();
		}
	
	 }
		
	
}
	 function chechIfo(){
		   if(confirm('是否确认隐藏？')) {
					return true;
			 }
			 else{
			 return false;
			 }
	  }
	  function chechIfos(){
		   if(confirm('是否确认显示？')) {
				return true;
			 }
			 else{
				return false;
			 }
	  }

	  
 function showLinkGoods(){
   var cat_id = document.getElementById('cat_id').value;
   var brand_id = document.getElementById('brand_id').value;
   var info = document.getElementById('keyword').value;
   if(cat_id=='' && brand_id=='' && info=='')
   {
      alert("至少选择或输入一种查询条件！");
      return;   
   }  
   //var cust_id = document.getElementById('cust_id').value;
   var data = Math.round(Math.random()* 10000);
   var bURL = "&cat_id="+cat_id+"&brand_id="+brand_id+"&info="+info+"&data="+data;
   var gURL = "showMoreGoods.jsp?height=380&width=610"+bURL;
   TB_show("关联商品",gURL,false);
}

function setDivHtml(k,goods_name,goods_id){
globalVal = "<tr id='spandiv"+k+"'><td width='5%' height='35' align='right' style='background:#F9F9F9;'><font color='#666666'>"+k+":</font>"+"</td><td width='55%' style='background:#F9F9F9;'><font color='#666666'>"+goods_name+"</font></td>"+"<td width='40%'>&nbsp;<img src='/program/company/index/images/cross.png' style='vertical-align:middle;cursor:pointer;' title=移除关联商品 onclick=moveout('"+k+"','"+goods_id+"') /></td></tr>";

}

function moveout(k,goods_id){
	var link_goods_group = document.getElementById("link_goods_group").value;
	link_goods_group = link_goods_group.replace(goods_id+'|','');
	document.getElementById("link_goods_group").value = link_goods_group;
	document.getElementById("spandiv"+k).style.display='none';
}